package cn.seqdata.forecast;

import java.util.Map;

import org.hawkular.datamining.forecast.AutomaticForecaster;
import org.hawkular.datamining.forecast.DataPoint;
import org.hawkular.datamining.forecast.Forecaster.Config;
import org.hawkular.datamining.forecast.ImmutableMetricContext;
import org.hawkular.datamining.forecast.MetricContext;
import org.hawkular.datamining.forecast.models.Model;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;

public class Forecaster {
	private final Model model;
	private final Map<String, Object> params;

	public Forecaster(Model model, Map<String, Object> params) {
		this.model = model;
		this.params = params;
	}

	public void learn(double[] values) {
		MetricContext ctx = new ImmutableMetricContext(null, null, (long) DateTimeConstants.MILLIS_PER_MINUTE);
		Config config = Config.getDefault();
// config.setPeriod(96);
// config.setConceptDriftStrategy(new AutomaticForecaster.PeriodicIntervalStrategy(1));
// config.setIc(InformationCriterion.BIC);
		config.setModelToUse(Model.TripleExponentialSmoothing);

		org.hawkular.datamining.forecast.Forecaster forecaster = new AutomaticForecaster(ctx, config);

		for (int i = 0; i < values.length; ++i) {
			DataPoint dp = new DataPoint(values[i], (long) i * DateTimeConstants.MILLIS_PER_MINUTE);
			forecaster.learn(dp);
		}

		for (DataPoint dp : forecaster.forecast(96)) {
// String str = String.format("%d\t%f", dp.getTimestamp(), dp.getValue());
			DateTime occur = new DateTime(dp.getTimestamp());
			String str = String.format("%s\t%f", occur, dp.getValue());
			System.out.println(str);
		}
	}

	double[] forecast(int n) {
		return null;
	}
}
